package com.news.wemedia.controller.v1.wemedia;

import com.news.model.common.dtos.ResponseResult;
import com.news.model.wemedia.dtos.WmNewsDto;
import com.news.model.wemedia.dtos.WmNewsPageReqDto;
import com.news.model.wemedia.dtos.WmNewsPersonDto;
import com.news.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 条件查询文章列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @Cacheable(value = "article",key = "")
    public ResponseResult findList(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.findList(dto);
    }

    /**
     * 保存文章
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    @CacheEvict(value = "article",key = "",allEntries = true)
    public ResponseResult submitNews(@RequestBody WmNewsDto dto){
        return wmNewsService.submitNews(dto);
    }
    /**
     * 查看文章详情
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult getArticleMessage(@PathVariable Integer id){
        return wmNewsService.getArticleMessage(id);
    }

    /**
     * 文章上架或下架
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/down_or_up")
    @CacheEvict(value = "article",key = "",allEntries = true)
    public ResponseResult setDownOrUp(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.downOrUp(wmNewsDto);
    }

    /**
     * 人工审核文章列表
     * @param wmNewsPersonDto
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult listPerson(@RequestBody WmNewsPersonDto wmNewsPersonDto){
        return wmNewsService.listPerson(wmNewsPersonDto);
    }

    /**
     * 查询文章详情
     * @param id
     * @return
     */
    @GetMapping("/one_vo/{id}")
    public ResponseResult article(@PathVariable Integer id){
        return wmNewsService.getArticleMessage(id);
    }

    /**
     * 文章审核成功
     * @param wmNewsPersonDto
     * @return
     */
    @PostMapping("/auth_pass")
    public ResponseResult auth_pass(@RequestBody WmNewsPersonDto wmNewsPersonDto){
        return wmNewsService.setAuthPass(wmNewsPersonDto);
    }

    /**
     * 文章审核失败
     * @param wmNewsPersonDto
     * @return
     */
    @PostMapping("/auth_fail")
    public ResponseResult auth_fail(@RequestBody WmNewsPersonDto wmNewsPersonDto){
        return wmNewsService.setAuthFail(wmNewsPersonDto);
    }

}
